import {
    CmdToolbox,
	CmdMemory,
	CmdPeripherals,
	MemoryParam,
	MCU_Core,
	Peripheral,
	DissassembleLine,
	DissassembleScroll,
	CmdDissassemble
} from "structs.slint";

import { TestData } from "test-data.slint";

export global UiIo {
	//common
	callback copy-to-clipboard(string);

	//toolbox
	in-out property <[string]> probe_list: TestData.probe_list;
	in-out property <[string]> core_list: TestData.core_list;

	in-out property <string> selected_probe: TestData.probe_list[0];
	in-out property <string> selected_core: TestData.core_list[0];

	in-out property <bool> debug_info_valid: false;
	in-out property <bool> attach_state: false;
	in-out property <string> help_tip: "tip here";
	
	in-out property <MCU_Core> mcu_core: TestData.mcu_core;

	callback probe-toolbox(CmdToolbox);
	callback open-url(string);

	//memory
	in-out property <[MemoryParam]> memory_param: [ {
			address: "0x20000000",
			offset: "",
			length: "64",
			data: ""
		}, {
			address: "0x20010000",
			offset: "",
			length: "128",
			data: ""
		}, {
			address: "0x08000000",
			offset: "",
			length: "128",
			data: ""
		}
	];

	callback probe-memory(int, CmdMemory);

	//peripherals
	in-out property <[Peripheral]> peripherals: [];//TestData.peripherals;
	in-out property <string> svd_file_path;

	callback probe-peripherals(CmdPeripherals);
	callback probe-peripheral-get(string, string);
	callback probe-peripheral-modify(string, string, string, int, int);

	//Dissassemble
	in-out property <length> assemble_line_height: 15px;
	in-out property <length> assemble_visible_height: 0px;
	in-out property <[DissassembleLine]> dissassemble_line: [];//TestData.dissassemble_line;
	in-out property <string> flash_start_address: "";
	in-out property <string> flash_size: "";
	in-out property <string> PC_str: "";
	in-out property <int>    PC: 0;
	in-out property <int>    assemble_pc_line: 0;
	in     property <int>    assemble_line_number: 0;
	in     property <int>    assemble_line_current: 0;

	callback probe-disassemble(CmdDissassemble, string, string);
	callback probe-assemble-scroll(int, int, int);
	callback probe-set-breakpoint(bool, int);

	public function assemble-scrollbar-move(visible_height: length, srollbar_value: length) {
		self.probe-assemble-scroll(0, visible_height/assemble_line_height, srollbar_value/assemble_line_height);
	}

	public function assemble-scroll( up: bool, visible_height: length, type: DissassembleScroll) {
		if (type == DissassembleScroll.Line) {
			self.probe-assemble-scroll(up ? 1 : -1, visible_height/assemble_line_height, 1);
		} else if (type == DissassembleScroll.Page) {
			self.probe-assemble-scroll(up ? 1 : -1, visible_height/assemble_line_height, visible_height/assemble_line_height);
		} else if (type == DissassembleScroll.ToPC) {
			self.probe-assemble-scroll(0, visible_height/assemble_line_height, -1);
		} else {
			self.probe-assemble-scroll(up ? 1 : -1, visible_height/assemble_line_height, visible_height/assemble_line_height/4);
		}
	}
}
